package com.coffee.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.coffee.common.annotation.Log;
import com.coffee.common.result.R;
import com.coffee.system.common.dto.SysDeptAddDTO;
import com.coffee.system.common.dto.SysDeptEditDTO;
import com.coffee.system.common.dto.SysDeptQueryDTO;
import com.coffee.system.service.ISysDeptService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 部门表 前端控制器
 * </p>
 *
 * @author Kevin
 * @since 2021-06-10
 */
@RestController
@RequestMapping("/system/sysDept")
public class SysDeptController {

    @Resource
    private ISysDeptService sysDeptService;

    /**
     * 分页查询
     */
    @GetMapping("/page")
    @SaCheckPermission("system:sysDept:page")
    @Log(title = "部门管理分页查询")
    public R page(Page reqPage, SysDeptQueryDTO req) {
        return R.success(sysDeptService.page(reqPage, req));
    }

    /**
     * 新增
     */
    @PostMapping("/add")
    @SaCheckPermission("system:sysDept:add")
    @Log(title = "部门管理新增")
    public R add(@Validated @RequestBody SysDeptAddDTO req) {
        sysDeptService.add(req);
        return R.success();
    }

    /**
     * 修改
     */
    @PostMapping("/edit")
    @SaCheckPermission("system:sysDept:edit")
    @Log(title = "部门管理修改")
    public R edit(@Validated @RequestBody SysDeptEditDTO req) {
        sysDeptService.edit(req);
        return R.success();
    }

    /**
     * 删除
     */
    @PostMapping("/remove")
    @SaCheckPermission("system:sysDept:remove")
    @Log(title = "部门管理删除")
    public R remove(@RequestParam String ids) {
        sysDeptService.remove(ids);
        return R.success();
    }

    /**
     * 查看
     */
    @GetMapping("/view")
    @SaCheckPermission("system:sysDept:view")
    @Log(title = "部门管理查看")
    public R view(@RequestParam String id) {
        return R.success(sysDeptService.view(id));
    }

    /**
     * 查询部门树
     */
    @GetMapping("/listDeptTree")
    public R listDeptTree() {
        return R.success(sysDeptService.listDeptTree());
    }

    /**
     * 查询下拉部门树，排除当前节点以及子节点
     */
    @GetMapping("/selectDeptTreeAndExcludeNode")
    public R selectTreeAndExcludeNode(@RequestParam(required = false) String nodeId) {
        return R.success(sysDeptService.selectDeptTreeAndExcludeNode(nodeId));
    }

    /**
     * 查询下拉部门树
     */
    @GetMapping("/selectDeptTree")
    public R selectTree() {
        return R.success(sysDeptService.selectDeptTree());
    }

}

